<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>门诊管理</el-breadcrumb-item>
      <el-breadcrumb-item>挂号管理</el-breadcrumb-item>
      <el-breadcrumb-item>挂号列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--卡片视图-->
    <el-card>
      <!--搜索区域-->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入手机号"   v-model="input" style="width:100%;" >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addDialogVisible = true"
            >添加</el-button
          >
        </el-col>
      </el-row>
      <!--挂号列表区-->
      <el-table
        :data="RegistrationList"
        border
        style="margin-top: 15px; font-size: 12px"
      >
        <el-table-column type="index"></el-table-column>
        <el-table-column label="姓名" prop="Regis_name"></el-table-column>
        <el-table-column
          label="身份证"
          prop="ID"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="手机号"
          prop="phone"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column label="预约时段" prop="Recipe_isFa"></el-table-column>
        <el-table-column label="挂号方式" prop="Regis_manner"></el-table-column>
        <el-table-column
          label="挂号时间"
          prop="Regis_date"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column label="挂号状态" prop="Regis_status" width="170px">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.Regis_status"
              active-text="预约"
              inactive-text="受理"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column label="支付状态" prop="Recipe_payStatus" width="200px">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.Recipe_payStatus"
              active-text="未支付"
              inactive-text="已支付"
              @change="payStatusChanged(scope.row)"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column label="挂号类型" prop="type"></el-table-column>
        <el-table-column label="科室" prop="departments"></el-table-column>
        <el-table-column label="金额" prop="money"></el-table-column>
        <!-- <el-table-column label="操作" width="120px">
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="修改" placement="top">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
              ></el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="删除" placement="top">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页区域-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        style="margin-top: 15px"
      >
      </el-pagination>
    </el-card>
    <!--添加挂号对话框-->
    <el-dialog
      title="添加挂号信息"
      :visible.sync="addDialogVisible"
      width="50%"
      @close="addDialogClosed"
    >
      <!--内容主题区域-->
      <el-form
        :model="addForm"
        :rules="addFormRules"
        ref="addFormRef"
        label-width="100px"
      >
        <el-form-item label="姓名" prop="Regis_name">
          <el-input v-model="addForm.Regis_name"></el-input>
        </el-form-item>
        <el-form-item
          label="身份证"
          prop="ID"
          style="position: absolute; left: 50%; top: 15%; width: 100%"
        >
          <el-input v-model="addForm.ID"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="addForm.phone"></el-input>
        </el-form-item>
        <el-form-item
          label="预约时段"
          :label-width="formLabelWidth"
          prop="Recipe_isFa"
          style="position: absolute; left: 50%; top: 26%; width: 39%"
        >
          <el-select v-model="addForm.Recipe_isFa" placeholder="请选择预约时段">
            <el-option label="上午" value="1"></el-option>
            <el-option label="下午" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="挂号方式">
          <el-input v-model="addForm.Regis_manner" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item
          label="挂号日期"
          prop="Regis_date"
          style="position: absolute; left: 50%; top: 37%; width: 117%"
        >
          <!-- <el-input v-model="addForm.Regis_date"></el-input> -->
          <el-col :span="20">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="addForm.Regis_date"
            ></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="挂号状态" prop="Regis_status" style="width: 40%">
          <el-select v-model="addForm.Recipe_isFa" placeholder="请选择挂号状态">
            <el-option label="受理" value="1"></el-option>
            <el-option label="预约" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="支付状态"
          prop="Recipe_payStatus"
          style="position: absolute; left: 50%; top: 49%; width: 39%"
        >
          <el-select
            v-model="addForm.Recipe_payStatus"
            placeholder="请选择支付状态"
          >
            <el-option label="已支付" value="1"></el-option>
            <el-option label="未支付" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="挂号类型" prop="type" style="width: 40%">
          <el-select v-model="addForm.type" placeholder="请选择挂号类型">
            <el-option label="普通挂号" value="1"></el-option>
            <el-option label="专家会诊" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="科室"
          prop="departments"
          style="position: absolute; left: 50%; top: 59%; width: 40%"
        >
          <el-select v-model="addForm.departments" placeholder="请选择挂号科室">
            <el-option label="内科" value="1"></el-option>
            <el-option label="肿瘤科" value="2"></el-option>
            <el-option label="血管外科" value="3"></el-option>
            <el-option label="神经外科" value="4"></el-option>
            <el-option label="心血管外科" value="5"></el-option>
            <el-option label="外科" value="6"></el-option>
            <el-option label="妇产科" value="7"></el-option>
            <el-option label="精神医学科" value="8"></el-option>
            <el-option label="挂号收费科" value="8"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="金额" prop="money">
          <el-input v-model="addForm.money"></el-input>
        </el-form-item>
      </el-form>
      <!--主题区域-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addRegistration"
          >添 加</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
     // 验证手机号的正则
       var checkMobile = (rule,value,cb) =>{
         const regMobile = /^(0|86|17951)?(13[0-9]|15[0123456789]|17[678]|18[0-9]|14[57])[0-9]{8}$/

         if(regMobile.test(value)){
           return cb()
         }
         cb(new Error('请输入合法的手机号'))
       }
    return {
       input: '',
      //获取挂号列表
      queryInfo: {
        quary: "",
        // 当前的页数
        pagenum: 1,
        // 当前每页显示多少条数据
        pagesize: 2,
      },
      RegistrationList: [
        {
          Regis_name: "王小炮",
          ID: "410155789978884421",
          phone: "17788894554",
          Recipe_isFa: "上午",
          Regis_manner: "医院挂号",
          Regis_date: "2020-09-27 16:17:55",
          Regis_status: false,
          Recipe_payStatus: true,
          type: "普通号",
          departments: "眼科",
          money: "10.00",
        },
        {
          Regis_name: "王小炮",
          ID: "410155789978884421",
          phone: "17788894554",
          Recipe_isFa: "上午",
          Regis_manner: "医院挂号",
          Regis_date: "2020-09-27 16:17:55",
          Regis_status: false,
          Recipe_payStatus: true,
          type: "普通号",
          departments: "眼科",
          money: "10.00",
        },
        {
          Regis_name: "王小炮",
          ID: "410155789978884421",
          phone: "17788894554",
          Recipe_isFa: "上午",
          Regis_manner: "医院挂号",
          Regis_date: "2020-09-27 16:17:55",
          Regis_status: false,
          Recipe_payStatus: true,
          type: "普通号",
          departments: "眼科",
          money: "10.00",
        },
        {
          Regis_name: "王小炮",
          ID: "410155789978884421",
          phone: "17788894554",
          Recipe_isFa: "上午",
          Regis_manner: "预约挂号",
          Regis_date: "2020-09-27 16:17:55",
          Regis_status: false,
          Recipe_payStatus: true,
          type: "普通号",
          departments: "眼科",
          money: "10.00",
        },
      ],
      total: 0,
      // 控制Dialog的显示与隐藏
      addDialogVisible: false,
      // 添加用户的表单数据
      addForm: {
        Regis_name: "",
        ID: "",
        phone: "",
        Recipe_isFa: "",
        Regis_manner: "医院挂号",
        Regis_date: "",
        Regis_status: "",
        Recipe_payStatus: "",
        type: "",
        departments: "",
        money: "",
      },
     
      // 添加表单的验证规则对象
      addFormRules: {
        Regis_name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          { min: 2, max: 5, message: "长度在 2 到 5 个字符", trigger: "blur" },
        ],
        ID: [
          { required: true, message: "请输入身份证", trigger: "blur" },
          { min: 18, max: 18, message: "长度在18个字符", trigger: "blur" },
        ],
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { validator: checkMobile, trigger: "blur" },
        ],
        Recipe_isFa: [
          { required: true, message: "请选择预约时段", trigger: "blur" },
        ],
        Regis_date: [
          { required: true, message: "请选择挂号日期", trigger: "blur" },
        ],
        Regis_status: [
          { required: true, message: "请选择挂号状态", trigger: "blur" },
        ],
         Recipe_payStatus: [
          { required: true, message: "请选择支付状态", trigger: "blur" },
        ],
         type: [
          { required: true, message: "请选择挂号类型", trigger: "blur" },
        ],
         departments: [
          { required: true, message: "请选择挂号科室", trigger: "blur" },
        ],
        money: [
          { required: true, message: "请输入金额", trigger: "blur" },
        ],
      },
    };
  }, 
  created() {
    this.getRegistrationList();
  },
  methods: {
    async getRegistrationList() {
      const { data: res } = await this.$http.get("Registration", {
        params: this.queryInfo,
      });
      if (res.meta.status !== 200) {
        return this.$message.error("获取用户列表失败！");
      }
      this.RegistrationList = res.data.Registration;
      this.total = res.data.total;
      console.log(res);
    },
    // 监听pagesize改变的事件
    handleSizeChange(newSize) {
      console.log(newSize);
      this.queryInfo.pagesize = newSize;
      this.getRegistrationList();
    },
    // 监听 页码值改变的事件
    handleCurrentChange(newPage) {
      console.log(newPage);
      this.queryInfo.pagenum = newPage;
      this.getRegistrationList();
    },
    // 监听switch状态的变化
    payStatusChanged() {},
    // 监听添加用户对话框关闭的时间
    addDialogClosed(){
      this.$refs.addFormRef.resetFields()
    },
    //点击按钮添加新用户
    addRegistration(){
      this.$refs.addFormRef.validate(valid =>{
        if(!valid) return
        //可以发起添加用户的网络请求
        /**
         * 代码区
         */
      })
    }
  },
};
</script>
<style  lang="less" scoped>
.el-breadcrumb {
  margin-bottom: 15px;
  font-size: 12px;
}
.el-card {
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15) !important;
}
.el-input {
  width: 30% 
}
.el-form-item {
  line-height: 2em;
}
</style>